/*
 * @Author: hanxin 
 * @Date: 2021-08-30 16:24:58 
 * @Last Modified by: hanxin
 * @Last Modified time: 2021-08-31 00:26:50
 * 餐桌表的业务操作
 */
package mhl.service;

import java.util.List;

import mhl.dao.diningTableDao;
import mhl.javabean.diningTable;

public class diningTableService {
    private diningTableDao diningTableDao = new diningTableDao();

    /**
     * 查询餐桌表所有信息方法
     * 
     * @return
     */
    public List<diningTable> getTable() {
        String sql = "select * from diningTable";
        return diningTableDao.queryMulit(sql, diningTable.class);
    }

    /**
     * 判断餐桌是否存在
     * 
     * @param Table_id
     * @return
     */
    public diningTable isTableExist(Integer Table_id) {
        String sql = "select * from diningTable where Table_id = ?";
        return diningTableDao.query(sql, diningTable.class, Table_id);
    }

    /**
     * 判断该餐桌是否已经被预订
     * 
     * @param Table_id
     * @return
     */
    public boolean isTableBooking(int Table_id) {
        String sql = "select state from diningTable where Table_id = ?";
        Object obj = diningTableDao.queryScalar(sql, Table_id);

        String str = (String) obj;
        return str.equals("空");
    }

    /**
     * 餐桌预订方法
     * 
     * @param Table
     * @param orderName
     * @param orderPhone
     */
    public boolean orderTable(int Table_id, String orderName, String orderPhone) {
        String sql = "update diningTable set state = '已预订' , orderName = ? , orderPhone = ? where Table_id = ? ";
        int row = diningTableDao.dml(sql, orderName, orderPhone, Table_id);

        return row > 0;
    }

    /**
     * 餐桌退订方法
     * 
     * @param Table_id
     * @return
     */
    public boolean UnsubscribeTable(int Table_id) {
        String sql = "update diningTable set state = '空' ,orderName = '' , orderPhone = ' ' where Table_id = ?";
        int row = diningTableDao.dml(sql, Table_id);
        return row > 0;
    }

    /**
     * 更新餐桌状态
     * 
     * @param Table_id
     * @param state
     * @return
     */
    public int updateState(int Table_id, String state) {
        String sql = "update diningTable set state = ? where Table_id = ?";
        int row = diningTableDao.dml(sql, state, Table_id);
        return row;
    }

    /**
     * 查询餐桌状态
     * 如果用餐中不允许退订
     * @param Table_id
     * @return
     */
    
    public boolean tableState(int Table_id) {
        String sql = "select state from diningTable where id = ?";
        Object obj = diningTableDao.queryScalar(sql, Table_id);

        String str = (String) obj;
        if (str.equals("用餐中")) {
            return true;
        }
        return false;
    }

}
